/*
* @Author: Hunter
* @Date: 2022-02-11 15:41:05
 * @LastEditTime: 2022-05-01 19:13:20
 * @LastEditors: Hunter
* @Description: 
 * @FilePath: \book_mark\src\utils\request.ts
* 可以输入预定的版权声明、个性签名、空行等
*/
import { Defer } from "./index"
type IRequestOptions = {
    params?: Record<string, any>;
    body?: BodyInit | null | any
} & RequestInit;
type ICallBack<T> = (url: string, options?: Omit<IRequestOptions, 'body' | 'method'>) => Promise<T>
export type IRequest = {
    GET: ICallBack<any>
    // POST: ICallBack<any>
    // PUT: ICallBack<any>
    // DELETE: ICallBack<any>
}

export class Request implements IRequest {
    GET = async (url: string, options?: Omit<IRequestOptions, 'body' | 'method'>) => {
        const { resolve, reject, promise } = Defer()
        try {
            resolve(await fetch(url))
        } catch (e) {
            reject(e)
        }
        return promise
    }
}
